<? 
include("C_colortools.inc"); 
include("libs.inc");

echo head();
?>

<div id="header">
	<div id="logo">
		<h1><a href="http://code.google.com/p/phpcolortools/">PhpColorTools</a></h1>
		<h2><a href="http://code.google.com/p/phpcolortools/">Open Source PHP</a></h2>
	</div>
	<div id="search" style="color:black;position:relative;top:-14px;">
		<?php
			$graph = new ColorGraph();
			$graph->setMidColor(0,0,255);
			
			// Day or Year
			$v = date("z",time());
			$t = date("L",time()) == 1 ? 366 : 365;
			$doy = $graph->getHorrizBar($v,$t);
			
			// Day or Year
			$v = date("j",time());
			$t = date("t",time());
			$dom = $graph->getHorrizBar($v,$t);
			
			// date
			$date = date("r", time());
			echo <<<qq
				<table>
					<tr>
						<td>Date:</td>
						<td>$date</td>
					</tr>
					<tr>
						<td>Year:</td>
						<td>$doy</td>
					</tr>
					<tr>
						<td>Month:</td>
						<td>$dom</td>
					</tr>
				</table>
qq;
		?>
			
	</div>
</div>
<div id="menu">
	<ul>
		<li class="active"><a href="#">Home</a></li>
		<li><a href="http://code.google.com/p/phpcolortools/source/browse/#svn/trunk">Download</a></li>
		<li><a href="http://code.google.com/p/phpcolortools/issues/list">Feature request</a></li>
		
		<!--
		<li><a href="#">Examples</a></li>
		<li><a href="#">Download</a></li>
		<li><a href="#">Contact</a></li>
		-->
	</ul>
</div>
<hr />
<div id="page">
	<div id="splash" class="twocols">
		<div class="col1">
			<h2 class="title">PHP Class Library for dynamic color</h2>
			<p>Generate creative visual representations of complex data using calculated color values. <a href="http://code.google.com/p/phpcolortools/">Read more&hellip;</a></p>
		</div>
		<div class="col2">
			<h2 class="title">Download</h2>
			<ul class="list">
				<li><a href="http://code.google.com/p/phpcolortools/source/browse/#svn/trunk">Source</li>
				<li><a href="http://code.google.com/p/phpcolortools/source/checkout">Subversion</a>: svn checkout http://phpcolortools.googlecode.com/svn/trunk/ phpcolortools-read-only</li>
			</ul>
		</div>
		<div style="clear: both;">&nbsp;</div>
	</div>
	
	<div id="content-onecol">
		<div>
			<h1 class="title">Utilities to calculate custom color gradients, color effects, simple graphs, and more</h1>
			<p><strong>Php Color Tools</strong> is a free <a href="http://code.google.com/p/phpcolortools/">open source class library</a>.  Tested and works great in IE6, IE8, Firefox, Chrome, Android mobile browser, and Opera!<em> Enjoy :)</em></p>
			
			<? 
			//
			// Dynamic Color
			//
			echo sectionTitle('Dynamic Color'); 
			echo sectionText('Create an icon, colored dynamically to represent its corresponding data.');
			
			$code = '
			// Create some simulated data
			$aInventedData = array();
			$aInventedData[\'Chance of snow\'] = 96;
			$aInventedData[\'Chance of epic powder\'] = 17;
			// Create a color calc object
			$cc = new ColorCalc();
			$output="";
			foreach( $aInventedData as $condition => $chance ) {
				// The $chance is the percentage, use it to get the
				//  color
				$color = $cc->getRGBCalc($chance);
				// This creates a png using GD in the color we pass it
				$output .= "<img src=\"dynamicRoundIcon.png.php?rgb=$color\" /> ";
				$output .= "$condition<br />";
			}
			echo $output;';
			echo sectionCodeAndOutput($code);
			
			echo sectionText('Take some colors, say green, orange, and red. Now represent the state of some data using those colors and any hues in between.  This example simply sets the color range to go from red to orange to green then uses a percentage, 0 to 100, to calculate what color would represent that value on a color gradient going from red to orang to green.');
			
			$code = '
			$aInventedData = array();
			$aInventedData[\'Wilson\'] = 73;
			$aInventedData[\'Lincoln\'] = 2;
			$aInventedData[\'Fujitsu\'] = 21;
			$aInventedData[\'Datadyne\'] = 100;
			$aInventedData[\'Opal\'] = 47;
			
			$cc = new ColorCalc();
			$output="";
			foreach( $aInventedData as $project => $completion ) {
				$color = $cc->getRGBCalc($completion);
				$output .= "The <span style=\"color:rgb($color)\">$project project</span> ";
				$output .= "is ";
				$output .= "<span style=\"color:rgb($color)\">$completion%</span> ";
				$output .= "complete.<br />";
			}
			echo $output;';
			echo sectionCodeAndOutput($code);
			
			echo sectionText('Now take the same numbers but let\'s play with the coloring and set them to something different.');
			
			$code = '
			$aInventedData = array();
			$aInventedData[\'Wilson\'] = 73;
			$aInventedData[\'Lincoln\'] = 2;
			$aInventedData[\'Fujitsu\'] = 21;
			$aInventedData[\'Datadyne\'] = 100;
			$aInventedData[\'Opal\'] = 47;
			
			$cc = new ColorCalc();
			// This color gradient will go from red, to deep red, to blue.
			//  basically low percentages are all red, higher percentages 
			//  become blue.
			$cc->setStartColor(255,0,0);
			$cc->setMidColor(210,0,0);
			$cc->setEndColor(0,0,255);

			$output="";
			foreach( $aInventedData as $project => $completion ) {
				$color = $cc->getRGBCalc($completion);
				$output .= "The <span style=\"color:rgb($color)\">$project project</span> ";
				$output .= "is ";
				$output .= "<span style=\"color:rgb($color)\">$completion%</span> ";
				$output .= "complete.<br />";
			}
			echo $output;';
			echo sectionCodeAndOutput($code);
			
			
			//
			// Dynamic Graph coloring
			//
			echo sectionTitle('Dynamic bar graph coloring'); 
			echo sectionText('Generate simple horrizontal bars representing percentage data. The color used to display the percent value and the color of the bar itself is generated by taking a start color (red), mid color (blue) and an end color (green). The percentage is used to determine a calculated color value within the three color range and displayed in that color.');
			echo sectionText('This example shows 11 different graphs called in succession with different parameters. See the examples page for other samples of how this class can bring simple bar representations together for your web pages');
			
			$code = '
			// Color graph object can generate color bar-graphs.
			$gr = new ColorGraph();
			// Set the three colors to use in the gradient. The three argument
			// are decimal RGB values between 0 and 255.
			$gr->setStartColor(255,0,0);
			$gr->setMidColor(0,0,255);
			$gr->setEndColor(0,170,0);
			$output="";
			for( $i=0; $i<=10; $i++ ) {
				// Returns each bar in the color representing the calculated
				//  color value represented by the percentage.
				$output .= $gr->getHorrizBar($i,10);
			}
			echo $output;';
			echo sectionCodeAndOutput($code);
			
			
			//
			// Gradients
			//
			echo sectionTitle('Simple Gradnient'); 
			echo sectionText('Generate a color gradient as a square div. Content could be positioned above this div for a gradient background.');
			
			$code = '
			$cc = new ColorCalc();
			$output="";
			for( $i=0; $i<=100; $i++ ) {
				$backgroundRGB = $cc->getRGBCalc($i);
				$output .= "
					<div style=\"	height:3px;
									color:white;
									background-color:rgb($backgroundRGB);\">
						&nbsp;
					</div>
				";
			}
			echo $output;';
			echo sectionCodeAndOutput($code);

			
			echo sectionText('Make a gradient background...');
			
			$code = '
			$cc = new ColorCalc();
			$cc->setStartColor(255,0,0);
			$cc->setMidColor(0,0,0);
			$cc->setEndColor(0,0,255);
			$output="<div style=\"	position:relative;
									align:center;\">";
			$output .= "<div style=\"	position:absolute;
										color:white;
										font-size:2em;
										margin:15px;
										align:center;\">In many cases, the user
										interface to a program is the most
										important part for a commercial company:
										whether the programs works correctly or
										not seems to be secondary. 
										<br /><br />
										~ L. Torvalds<br /><br />
										</div>";
			for( $i=0; $i<=100; $i++ ) {
				$backgroundRGB = $cc->getRGBCalc($i);
				$output .= "
					<div style=\"	height:3px;
									color:white;
									background-color:rgb($backgroundRGB);\">
						&nbsp;
					</div>
				";
			}
			$output .= "</div>";
			echo $output;';
			echo sectionCodeAndOutput($code);
			
			//
			// Dynamic row coloring
			//
			echo sectionTitle('Dynamic Row Backgrounds'); 
			echo sectionText('ALternating row colors can be easily achieved with the modulus operator. ColorCycle() here demonstrates some moves beyond standard zebra striping rowcolors.');
			
			$code = '
			$output=\'\';
			// An array to simulate database rows for the loop below
			$aDbResults = array(
				0 => array("Department 20","$15k"),
				1 => array("Department 20","$4k"),
				2 => array("Department 99","$36k"),
				3 => array("Department 01","$36k"),
				4 => array("Department 01","$21k"),
				5 => array("Department 01","$3k"),
				6 => array("Department 12","$0"),
				7 => array("Department 12","$101k")
			);
			$cc = new ColorCycle();
			foreach( $aDbResults as $r ) {
				// Each time getColor() is called it returns an alternating
				//  row color.
				$bgcolor = $cc->getColor();
				$output .= " <tr bgcolor=\"$bgcolor\">";
				$output .= "  <td>$r[0]</td><td>$r[1]</td>";
				$output .= " </tr>";
			}
			echo "<table border=\"0\" cellspacing=\"1\">$output</table>";';
			echo sectionCodeAndOutput($code);
			
			
			
			echo sectionText('Or use custom alternating colors. Here we go from a two color scheme using default coloring, to a three (or more if you want) color scheme using our own specified colors.');
			
			$code = '
			$output=\'\';
			// An array to simulate database rows for the loop below
			$aDbResults = array(
				0 => array("Department 20","$15k"),
				1 => array("Department 20","$4k"),
				2 => array("Department 99","$36k"),
				3 => array("Department 01","$36k"),
				4 => array("Department 01","$21k"),
				5 => array("Department 01","$3k"),
				6 => array("Department 12","$0"),
				7 => array("Department 12","$101k")
			);
			$cc = new ColorCycle(array("#FFFEF2","#FFFFFF","#EEEEEE"));
			foreach( $aDbResults as $r ) {
				// Each time getColor() is called it returns an alternating
				//  row color.
				$bgcolor = $cc->getColor();
				$output .= " <tr bgcolor=\"$bgcolor\">";
				$output .= "  <td>$r[0]</td><td>$r[1]</td>";
				$output .= " </tr>";
			}
			echo "<table border=\"0\" cellspacing=\"1\">$output</table>";';
			echo sectionCodeAndOutput($code);
			
			
			
			
			
			echo sectionText('The "sticky field" tells the alternating color not to rotate to the next color in the cycle until the sticky field changes value.');
			
			$code = '
			$output=\'\';
			// An array to simulate database rows for the loop below
			$aDbResults = array(
				0 => array("Department 20","$15k"),
				1 => array("Department 20","$4k"),
				2 => array("Department 99","$36k"),
				3 => array("Department 01","$36k"),
				4 => array("Department 01","$21k"),
				5 => array("Department 01","$3k"),
				6 => array("Department 12","$0"),
				7 => array("Department 12","$101k")
			);
			$cc = new ColorCycle(array("#F2FFFE","#FFFFFF"));
			foreach( $aDbResults as $r ) {
				// Gets the color and aware of when the sticky field changes
				$stickyColor = $cc->getStickyColor($r[0]);
				// Sticky field only displays the first time for any value
				//  that may repeat. Use this to get the display of the
				//  sticky field so that after the first time it displays
				//  it doesn\'t repeat
				$stickyField = $cc->getStickyFieldIfChanged();
				$output .= " <tr bgcolor=\"$stickyColor\">";
				$output .= "  <td>$stickyField</td><td>$r[1]</td>";
				$output .= " </tr>";
			}
			echo "<table border=\"0\" cellspacing=\"0\">$output</table>";';
			echo sectionCodeAndOutput($code);
			
			
			
			
			
			
			
			echo sectionText('How about combining the row coloring and dynamic coloring of data...');
			
			$code = '
			$output=\'\';
			// An array to simulate database rows for the loop below
			$aDbResults = array(
				0 => array("Department 20","$15k"),
				1 => array("Department 20","$4k"),
				2 => array("Department 99","$36k"),
				3 => array("Department 01","$36k"),
				4 => array("Department 01","$21k"),
				5 => array("Department 01","$3k"),
				6 => array("Department 12","$0"),
				7 => array("Department 12","$101k")
			);
			// Get the alternating row color object
			$colorCycle = new ColorCycle(array("#F2FFFE","#FFFFFF"));
			// Get the display color object
			$colorCalc = new ColorCalc();
			// These colors will indicate red=low, grey=middle,
			//  black=acceptible.
			$colorCalc->setStartColor(255,0,0);
			$colorCalc->setMidColor(100,100,100);
			$colorCalc->setEndColor(0,0,0);
			foreach( $aDbResults as $r ) {
				$stickyColor = $colorCycle->getStickyColor($r[0]);
				$stickyField = $colorCycle->getStickyFieldIfChanged();
				// Parse an int out of the salary value, using $40k as
				//  the top of the threshold for coloring purposes. It 
				//  is up to you how you make this happen but in the end
				//  it should end up as a percent between 0 and 100 (or
				//  go over 100, and the value for 100 will be used. Go
				//  below 0 and the value for 0 will be used.
				$pct = (((int)substr($r[1],1)) * 100) / 40;
				$color = $colorCalc->getRGBCalc($pct);
				$output .= " <tr bgcolor=\"$stickyColor\">";
				$output .= "  <td>$stickyField</td>";
				$output .= "  <td style=\"color:rgb($color)\">$r[1]</td>";
				$output .= " </tr>";
			}
			echo "<table border=\"0\" cellspacing=\"0\">$output</table>";';
			echo sectionCodeAndOutput($code);
			




			
			
			
			//
			// Debugging Color Choices
			//
			echo sectionTitle('Debugging Color Choices'); 
			echo sectionText('Getting a visual of how your colors will look at different levels or as a continueous gradient can be accomplished using dumpHtml()');
			
			$code = '
			$cc = new ColorCalc();
			// Pick some custom colors to use.
			$cc->setStartColor(252,252,33);
			$cc->setMidColor(0,0,255);
			$cc->setEndColor(0,170,0);
			// dumpHtml() shows the calculated colors that will be used for
			//  the range. The left side of the bar shows what the colors
			//  will look like at or near 0%, and the right side, the same 
			//  for 100%.
			echo $cc->dumpHtml();';
			echo sectionCodeAndOutput($code);
			
			echo sectionText('Or if working from the command line, use dump() to see the color values you are working with. This can be useful if the colors you use for the gradients are dynmic themselves.');
			
			$code = '
			$cc = new ColorCalc();
			echo $cc->dump();';
			echo sectionCodeAndOutput($code);
			
			
			?>
			
		</div>
	</div>
	<!--
	<div id="sidebar">
		<ul>
			<li>
				<h2>Recent Updates</h2>
				<ul style="margin-left:5px;">
					<li>
						<h3><span>24SEP2009:</span> Browser testing</h3>
						<p><a href="#">I tested the libs in IE6 and 8, Firefox, Chrome, Safari, Android, and others and it works like a charm.  Feel free to request features or submit bugs on the <a href="http://code.google.com/p/phpcolortools/issues/list">google code page for this project</a>.</a></p>
					</li>
					<li>
						<h3><span>23SEP2009:</span> Made it!</h3>
						<p><a href="#">Hey, what's up ... what'd I miss? Added some fun open source PHP for those looking to pretty up your data.</a></p>
					</li>
				</ul>
			</li>
			<li>&nbsp;</li>
			<li>
				<h2>Linkey</h2>
				<ul style="margin-left:5px;">
					<li><a href="http://code.google.com/p/phpcolortools/issues/list">Request Features</a> <small>(click 'New Issue' to create a request)</small></li>
					<li><a href="http://code.google.com/p/phpcolortools/">Download Source Code</a></li>
					<li><a href="http://code.google.com/p/phpcolortools/source/browse/#svn/trunk">Browse Source</a></li>
					<li><a href="http://code.google.com/p/phpcolortools/source/checkout">Subversion checkout</a></li>
					<li><a href="http://code.google.com/projecthosting/">Project Hosting on Google Code</a></li>
				</ul>
			</li>
		</ul>
	</div>
	<div style="clear: both;">&nbsp;</div>
</div>
-->
<?
/*
<hr />
<div id="footer">
	<p id="legal">Copyright &copy; 2010 D. DeZurik. All Rights Reserved | Designed by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a></p>
	<p id="links"><!-- <a href="#">Privacy Policy</a> | <a href="#">Terms of Use</a> | --><a href="http://www.freecsstemplates.org/">freecsstemplates.org</a></p>
</div>
*/
?>
</body>
</html>
